package menu

import (
	"context"

	"jinrigaoping/api/superadmin/internal/svc"
	"jinrigaoping/api/superadmin/internal/types"
	"jinrigaoping/rpc/sys/sys"

	"github.com/zeromicro/go-zero/core/logx"
)

type MenuUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewMenuUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MenuUpdateLogic {
	return &MenuUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *MenuUpdateLogic) MenuUpdate(req *types.SysMenuUpdateReq) (resp *types.SysMenuUpdateRes, err error) {

	if _, err := l.svcCtx.SysRpc.SysMenuUpdate(l.ctx, &sys.SysMenuUpdateReq{
		MenuId:      req.MenuId,
		ParentId:    req.ParentId,
		Name:        req.Name,
		Component:   req.Component,
		IsLink:      req.IsLink,
		MenuSort:    req.MenuSort,
		Path:        req.Path,
		Redirect:    req.Redirect,
		Title:       req.Title,
		Icon:        req.Icon,
		IsHide:      req.IsHide,
		IsKeepAlive: req.IsKeepAlive,
		IsAffix:     req.IsAffix,
		LinkUrl:     req.LinkUrl,
		MenuType:    req.MenuType,
		IsIframe:    req.IsIframe,
	}); err != nil {
		return nil, err
	}

	return &types.SysMenuUpdateRes{}, nil
}
